const { ErrorRes } = require('../res-model/index')
const { loginCheckFailInfo } = require('../res-model/failInfo')

async function customError(ctx, next) {
  try {
    await next()
  } catch (error) {
    if (error && error.status === 401) {
      ctx.body = new ErrorRes(loginCheckFailInfo)
      return
    }
    throw error
  }
}

module.exports = customError
